package com.soccer.soccerclub.controller;


import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.soccer.soccerclub.entity.Feedback;
import com.soccer.soccerclub.service.FeedbackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2021-04-22
 */
@RestController
@RequestMapping("/feedback")
public class FeedbackController {
    @Autowired
    private FeedbackService feedbackService;

    /**
     * 添加反馈信息
     * @param feedback
     * @return
     */
    @PostMapping("/add")
    public R addFeedback(@RequestBody Feedback feedback){
        feedback.setCreatTime(LocalDateTime.now());
        boolean save = feedbackService.save(feedback);
        return R.ok(save);
    }

    /**
     * 反馈列表
     * @param page
     * @return
     */
    @GetMapping("/list")
    public R list(Page<Feedback> page){
        Page<Feedback> feedbackPage = feedbackService.page(page);
        return R.ok(feedbackPage);
    }



    /**
     * 删除反馈
     * @param id
     * @return
     */
    @DeleteMapping("/delete")
    public R delete(Integer id){
        boolean remove = feedbackService.removeById(id);
        return R.ok(remove);
    }

}

